class Folder < ActiveRecord::Base
  has_many :documents
  acts_as_tree :order => 'name', :count_cache => true
  
  def rename(new_name)
    self.name = new_name
    self.update
  end
  
  def has_documents
    self.documents.size != 0
  end
  
  def has_folders
    self.children.size != 0
  end
  
  def Folder.create_root(user_id)
    root_folder = Folder.create(:name => '/', :user_id => user_id)
  end
  
  def delete
    if has_documents || has_folders
      return false
    else
      self.flag = 'deleted'
      self.update
      return true
    end
  end
  
  def is_root
    self.name == '/'
  end
end
